package com.vzoom.logdesensitization.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.vzoom.logdesensitization.jackson.JsonDesensitizationStringSerializer;
import com.vzoom.logdesensitization.jackson.JsonStrDesensitizationStringSerializer;

public class ObjectMappers {

    private static final ObjectMapper JSON_OBJECT_MAPPER;
    private static final ObjectMapper JSON_STR_OBJECT_MAPPER;

    static {
        JSON_OBJECT_MAPPER = new ObjectMapper();
        SimpleModule jsonSimpleModule = new SimpleModule();
        jsonSimpleModule.addSerializer(String.class, new JsonDesensitizationStringSerializer());
        JSON_OBJECT_MAPPER.registerModule(jsonSimpleModule);

        JSON_STR_OBJECT_MAPPER = new ObjectMapper();
        SimpleModule jsonStrSimpleModule = new SimpleModule();
        jsonStrSimpleModule.addSerializer(String.class, new JsonStrDesensitizationStringSerializer());
        JSON_STR_OBJECT_MAPPER.registerModule(jsonStrSimpleModule);
    }

    public static ObjectMapper getJsonObjectMapper() {
        return JSON_OBJECT_MAPPER;
    }

    public static ObjectMapper getJsonStrObjectMapper() {
        return JSON_STR_OBJECT_MAPPER;
    }
}
